meson: tests: make tests find resources from the source dir
authorTim-Philipp Müller <tim@centricular.com>
Sun, 12 Mar 2017 18:36:21 +0000 (18:36 +0000)
committerEmmanuele Bassi <ebassi@gnome.org>
Wed, 3 May 2017 14:10:53 +0000 (15:10 +0100)
Should probably also do this in the autotools build, since
the same problem exists there as well if we use srcdir != builddir.

tests/meson.build
tests/testdialog.c
tests/testgiconpixbuf.c
tests/testgtk.c
tests/testiconview.c
tests/testpopover.c
tests/testselectionmode.c
tests/testsplitheaders.c
tests/teststackedheaders.c

index 34bd68aff064a6ee9204b94245dd82dbc50a384d..2435e3d0e4f7e6ec9479c0acb7cd9a5f849afb85 100644 (file)
@@ -137,12 +137,16 @@ if x11_enabled
   gtk_tests += [['testerrors']]
 endif
 
-# TODO: need to pass source dir so progs can find .ui files and such
-# (with autotools this only works in the builddir == srcdir case)
+# Pass the source dir here so programs can change into the source directory
+# and find .ui files and .png files and such that they load at runtime
+test_args = ['-DGTK_SRCDIR="@0@"'.format(meson.current_source_dir())]
+
 foreach t : gtk_tests
   test_name = t.get(0)
   test_srcs = ['@0@.c'.format(test_name), t.get(1, [])]
-  executable(test_name, test_srcs, dependencies: [libgtk_dep, libm])
+  executable(test_name, test_srcs,
+    c_args : test_args,
+    dependencies : [libgtk_dep, libm])
 endforeach
 
 subdir('visuals')
index 941acfdba178453cdacef8507215a641167e53bc..07eba4b7b978fbf77e679b47d31c98f5d78ca5da 100644 (file)
@@ -1,4 +1,5 @@
 #include <gtk/gtk.h>
+#include <glib/gstdio.h>
 
 static void
 show_message_dialog1 (GtkWindow *parent)
@@ -316,6 +317,10 @@ main (int argc, char *argv[])
   GtkWidget *box;
   GtkWidget *button;
 
+#ifdef GTK_SRCDIR
+  g_chdir (GTK_SRCDIR);
+#endif
+
   gtk_init ();
 
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
index 8e9b7af587f2ce943769de959ad0b154c9d37ff2..fd9ab1d558e0a8479d9edc1c40ca96840381bd92 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include <gtk/gtk.h>
+#include <glib/gstdio.h>
 
 int
 main (int argc,
@@ -28,6 +29,10 @@ main (int argc,
   GEmblem *emblem;
   gchar *str;
 
+#ifdef GTK_SRCDIR
+  g_chdir (GTK_SRCDIR);
+#endif
+
   gtk_init ();
 
   pixbuf = gdk_pixbuf_new_from_file ("apple-red.png", NULL);
index 082ea55e0b1df8699b2a393cc738cbe57093c73d..93f8c969282813be4cddec23554fbdbf4013b07b 100644 (file)
@@ -37,6 +37,8 @@
 #include <unistd.h>
 #endif
 
+#include <glib/gstdio.h>
+
 #include "gtk/gtk.h"
 #include "gdk/gdk.h"
 #include "gdk/gdkkeysyms.h"
@@ -8805,6 +8807,10 @@ main (int argc, char *argv[])
 
   g_set_application_name ("GTK+ Test Program");
 
+#ifdef GTK_SRCDIR
+  g_chdir (GTK_SRCDIR);
+#endif
+
   gtk_init ();
 
   provider = gtk_css_provider_new ();
index 0a89fa6a5bb89d5d19ea0b5b58bd316e00505cac..c35916cc7dff5a5450810b1fcc240603a006e81c 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #include <gtk/gtk.h>
+#include <glib/gstdio.h>
 #include <sys/types.h>
 #include <string.h>
 
@@ -420,6 +421,10 @@ main (gint argc, gchar **argv)
   GtkCellRenderer *cell;
   GtkTreeViewColumn *tvc;
   
+#ifdef GTK_SRCDIR
+  g_chdir (GTK_SRCDIR);
+#endif
+
   gtk_init ();
 
   /* to test rtl layout, set RTL=1 in the environment */
index 6d12d6c8acacbdbb8bafa8e1fd1bc4356a905784..da5839de1c7d9e68e4c07e69e1e344acb1933a54 100644 (file)
@@ -1,4 +1,5 @@
 #include <gtk/gtk.h>
+#include <glib/gstdio.h>
 
 static void
 activate (GSimpleAction *action,
@@ -48,6 +49,10 @@ main (int argc, char *argv[])
   GtkWidget *check;
   GtkWidget *combo;
 
+#ifdef GTK_SRCDIR
+  g_chdir (GTK_SRCDIR);
+#endif
+
   gtk_init ();
 
   win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
index c639bbe8eb0320ab061d45566281c2804b4791dc..f3b983f912d99c592c3e2f03a5cd5b4205c563dd 100644 (file)
@@ -1,4 +1,5 @@
 #include <gtk/gtk.h>
+#include <glib/gstdio.h>
 
 typedef struct {
   GtkListBoxRow parent;
@@ -179,6 +180,10 @@ main (int argc, char *argv[])
   GSimpleActionGroup *group;
   GSimpleAction *action;
 
+#ifdef GTK_SRCDIR
+  g_chdir (GTK_SRCDIR);
+#endif
+
   gtk_init ();
 
   builder = gtk_builder_new_from_file ("selectionmode.ui");
index 42de06d74f11e5e236a26c513642e5d10f8b8143..7d89418886fb34a6448474e0fc0cd48d01a13054 100644 (file)
@@ -1,4 +1,5 @@
 #include <gtk/gtk.h>
+#include <glib/gstdio.h>
 
 static void
 split_decorations (GtkSettings *settings,
@@ -42,6 +43,10 @@ main (int argc, char *argv[])
   GtkWidget *check;
   GtkWidget *header;
 
+#ifdef GTK_SRCDIR
+  g_chdir (GTK_SRCDIR);
+#endif
+
   gtk_init ();
 
   builder = gtk_builder_new_from_file ("testsplitheaders.ui");
index 830e9da7612b93b9164ca3505a0775a72b859fdb..c342d685ca0eab431fccc7eb637032903c89bcdc 100644 (file)
@@ -1,4 +1,5 @@
 #include <gtk/gtk.h>
+#include <glib/gstdio.h>
 
 static GtkWidget *header_stack;
 static GtkWidget *page_stack;
@@ -23,6 +24,10 @@ main (int argc, char *argv[])
   GtkBuilder *builder;
   GtkWidget *win;
 
+#ifdef GTK_SRCDIR
+  g_chdir (GTK_SRCDIR);
+#endif
+
   gtk_init ();
 
   builder = gtk_builder_new ();